<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2016-2026 欣才开裆裤开发组
 * 网站地址: http://git.oschina.net/ts128
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 。
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: 十年丿小木
 * Date: 2016-10-24
 */
namespace Home\Controller;
use Home\Controller\BaseController;
/**
* 文章列表
*/
class ArticleController extends BaseController {
    public function _initialize(){
        $this->M = M("article");
    }
/*
*   文章列表
*/
    public function index(){
        echo R("Navlink/index");//R方法调用显示导航和友链
        $aaa=M("article");
        $aaa->alias("a")->join(array(//
            "LEFT JOIN y_article_cate c on a.cate_id=c.id",//关联分类
            "LEFT JOIN y_admin_member m on a.author=m.id",//关联作者
            "LEFT JOIN y_article_pic p on a.id=p.article_id"//关联图片
        ))->field(array(
            "a.*",
            "a.id"=> "id",//重命名id
            "c.name"=> "name",
            "m.username"=> "username",
            "p.picture" => "picture"
        ));
        $data = $aaa->select();//查询文章信息
        $this -> assign("article_list",$data);//传值
        $this->display();//输出模板
    }
/*
*   文章详情页
*/
    public function content(){
        echo R("Navlink/index");//R方法调用显示导航和友链
        $id = I("id");//获取id
        if(!empty($id)){//如果存在id
            $aaa=M("article");
            $aaa->alias("a")->join(array(
                "LEFT JOIN y_article_cate c on a.cate_id=c.id",
                "LEFT JOIN y_admin_member m on a.author=m.id",
                "LEFT JOIN y_article_pic p on a.id=p.article_id"
            ))->field(array(
                "a.*",
                "a.id"=> "id",
                "c.name"=> "name",
                "m.username"=> "username",
                "p.picture" => "picture"
            ));
            $data = $aaa->where("a.id=".$id)->select();//按id查询
            //$data = $data[0];
            $this->assign("article_content", $data);
        }
        $this->display();
    }

}